package com.toilet.easyvideofx.controller;

import com.toilet.easyvideofx.global.GlobalCache;
import com.toilet.easyvideofx.constant.SystemConstant;
import com.toilet.easyvideofx.manager.LoginManager;
import javafx.event.ActionEvent;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

/**
 * 注册界面
 */
public class RegisterController implements Initializable {
    public VBox content;
    public TextField account;
    public PasswordField password;
    public PasswordField confirmPassword;
    public Button reset;
    public Button register;
    private final LoginManager loginManager = new LoginManager();

    @Override
    public void initialize(URL location, ResourceBundle resources) {

    }

    public void reset(ActionEvent actionEvent) {

    }

    public void returnLogin(ActionEvent actionEvent) throws IOException {
        Stage stage = GlobalCache.get(SystemConstant.MAIN_STAGE, Stage.class);
        FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/fxml/login-view.fxml"));
        Scene registerScene = new Scene(fxmlLoader.load());
        stage.setTitle("登录");
        //登录界面设定无法改变大小
        stage.setResizable(false);
        stage.setScene(registerScene);
    }

    public void register(ActionEvent actionEvent) {
        Boolean registered = loginManager.register(account.getText(), password.getText(), confirmPassword.getText());
        System.out.println("注册结果" + registered);
    }
}
